package com.clubs.coding.Controller;

import com.clubs.coding.Service.NewsService;
import com.clubs.coding.common.ApiRestResponse;
import com.clubs.coding.model.pojo.News;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@ResponseBody
@RequestMapping("/news")
public class NewsController {
@Autowired
    NewsService newsService;
@GetMapping("/list")
    public ApiRestResponse list(@RequestParam(value = "isHome", required = false ,defaultValue = "0") Integer isHome,@RequestParam Integer pageNum,@RequestParam(value = "pageSize", required = false ,defaultValue = "10")Integer pageSize){

        PageInfo pageInfo = newsService.list(pageNum, pageSize,isHome);
        return ApiRestResponse.success(pageInfo);
    }
    @GetMapping("/singleArticle")
    public ApiRestResponse list(@RequestParam Integer newsId){

        News news = newsService.singleArticle(newsId);
        return ApiRestResponse.success(news);
    }
}
